package com.forum.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.forum.business.ForumManager;
import com.forum.model.dao.ForumUserDAO;
import com.forum.model.pojo.ForumUser;

@WebServlet("/UserEditController")
public class UserEditController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ForumUser user = ForumManager.fillEditedUserData(request);
		ForumUserDAO userDao = new ForumUserDAO();
		String message = "Profile successfully updated";
		String signal = "true";
		
		if (userDao.update(user) == false){
			signal = "false";
			message = "Profile editing failed!";
		}
		
		request.setAttribute("message", message);
		request.setAttribute("signal", signal);
		RequestDispatcher dispatcher = request.getRequestDispatcher("/userEdit.jsp");
		if (dispatcher != null) dispatcher.forward(request, response);
	}

}
